package homepage

import (
	"html/template"
	"myOJ/datastructure"
	"myOJ/db/useredis"
	"net/http"
	"strings"
)

func HomePage(w http.ResponseWriter, r *http.Request) {
	cook := r.Header.Get("Cookie")

	t := template.Must(template.ParseFiles("view/homepage/homepage.html"))

	var accountName string
	var hadLogin bool

	if strings.Compare(strings.TrimSpace(cook), "") != 0 {
		accountName = strings.Split(cook, "=")[0]
		hadLogin = true
	} else {
		accountName = ""
		hadLogin = false
	}
	pdata := datastructure.HomePage{useredis.QueryHomePageProblems(), accountName, hadLogin}
	t.Execute(w, &pdata)
}
